package {

import flash.display.*;
import flash.net.*;
import flash.events.*;
import flash.filters.*;

import com.whirled.*;

[SWF(width='0', height='0')]
public class PixelBent extends Sprite
{
    public function PixelBent ()
    {
        // Create the shader first so flash 9 users will error out hopefully...
        _shader = new Shader(new SHADER());
        _shader.data.offsets.value = [ 120, 0, 0 ];

        var ctrl :FurniControl = new FurniControl(this);
        //shader.data.dimension.value = [20];
        //shader.data.intensity.value = [0.5];

        var bounds :Array = ctrl.getRoomBounds();
        _overlay.graphics.beginFill(0); // TODO: Alpha for flash 9
        _overlay.graphics.drawRect(-bounds[0]/2, -bounds[1], bounds[0], bounds[1]);
        //_overlay.graphics.drawRect(0, 0, bounds[0], bounds[1]);
        _overlay.graphics.endFill();

        //this.blendMode = BlendMode.LAYER;

        _overlay.blendShader = _shader;
//        //shader.data.frontImage.image = new BitmapData(50, 50, true, 0xFF990000);
//        var filter :ShaderFilter = new ShaderFilter(shader);
//        icon.filters = [ filter ];

        addChild(_overlay);

        addEventListener(Event.ENTER_FRAME, onEnterFrame);

//        _startedOn = getTimer();
    }

    public function onEnterFrame (event :Event) :void
    {
        var offsets :Array = _shader.data.offsets.value;
        offsets[0] += 1;
        offsets[1] = (offsets[1]+0.01) % 1.0;
        offsets[2] = (offsets[2]+0.0005) % 1.0;
        _overlay.blendShader = _shader;
        _overlay.visible = true;
//        removeEventListener(Event.ENTER_FRAME, onEnterFrame);
    }
    
    protected var _overlay :Shape = new Shape();

    protected var _shader :Shader;

    [Embed(source="shader.pbj", mimeType="application/octet-stream")]
    protected static const SHADER :Class;
}
}
